package club.haomoon.front.service.impl;

import club.haomoon.core.entity.file.FileData;
import club.haomoon.core.mapper.file.FileCateDataMapper;
import club.haomoon.core.mapper.file.FileDataMapper;
import club.haomoon.front.service.IFileService;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.Map;

/**
 * -------------------------
 * @Description: 文件服务实现类
 * @Author: Wangjianwei
 * @Date: 2025/02/24 14:46  
 * -------------------------
 */
@Service
public class FileServiceImpl implements IFileService {

    @Resource
    FileDataMapper fileDataMapper;

    @Resource
    FileCateDataMapper fileCateDataMapper;

    /**
     * 文件新增
     *
     * @author Wangjw
     * @param params 文件信息参数
     */
    @Override
    public Integer fileAdd(Map<String, String> params) {
        String name = params.get("name");
        if (name.length() >= 100) {
            name = name.substring(0, 99);
        }

        FileData album = new FileData();
        album.setCid(Integer.parseInt(params.get("cid") == null ? "0" : params.get("cid")));
        album.setSourceId(Integer.parseInt(params.get("uid") == null ? "0" : params.get("uid")));
        album.setType(Integer.parseInt(params.get("type")));
        album.setSource(Integer.parseInt(params.get("source") == null ? "0" : params.get("source")));
        album.setName(name);
        album.setUri(params.get("url"));
        album.setCreateTime(System.currentTimeMillis() / 1000);
        album.setUpdateTime(System.currentTimeMillis() / 1000);
        fileDataMapper.insert(album);
        return album.getId();
    }

}
